/**
 * @(#)TestSubscribeReqProto.java, 2018/12/26
 * <p/>
 * Copyright 2018 Netease, Inc. All rights reserved.
 * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.chengzhi.netty.proto;

import com.google.protobuf.InvalidProtocolBufferException;

import java.util.ArrayList;

/**
 * @author 阮承志(wb.ruanchengzhi @ mesg.corp.netease.com)
 **/
public class TestSubscribeReqProto {
    private static byte[] encode(SubscribeReqProto.SubscribeReq req) {
        return req.toByteArray();
    }

    private static SubscribeReqProto.SubscribeReq decode(byte[] body) throws InvalidProtocolBufferException {
        return SubscribeReqProto.SubscribeReq.parseFrom(body);
    }

    private static SubscribeReqProto.SubscribeReq createSubscribeReq() {
        ArrayList<String> list = new ArrayList<>();
        list.add("11");
        list.add("22");
        list.add("33");
        return SubscribeReqProto.SubscribeReq.newBuilder()
                .setSubReqId(1)
                .setUserName("xxxx")
                .setProductName("book")
                .addAllAddress(list)
                .build();
    }

    public static void main(String[] args) throws InvalidProtocolBufferException {
        SubscribeReqProto.SubscribeReq subscribeReq1 = createSubscribeReq();
        System.out.println(subscribeReq1.toString());
        System.out.println(encode(subscribeReq1).length);
        SubscribeReqProto.SubscribeReq subscribeReq2 = decode(encode(subscribeReq1));
        System.out.println(subscribeReq2.toString());
        System.out.println(subscribeReq1.equals(subscribeReq2));
    }
}
